package com.xinzhidi.web.netty.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.core.domain.R;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.common.utils.poi.ExcelUtil;
import com.xinzhidi.web.netty.entity.dto.AgreementUnitValveHistoryAddDto;
import com.xinzhidi.web.netty.entity.dto.AgreementUnitValveHistoryListDto;
import com.xinzhidi.web.netty.entity.dto.AgreementUnitValveHistoryUpdDto;
import com.xinzhidi.web.netty.entity.vo.AgreementUnitValveHistoryInfoVo;
import com.xinzhidi.web.netty.entity.vo.AgreementUnitValveHistoryListVo;
import com.xinzhidi.web.netty.service.AgreementUnitValveHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 单元阀门协议-历史数据Controller
 *
 * @author cx
 * @date 2023-06-17
 */
@RestController
@Api(tags = "单元阀门协议-历史数据")
@RequestMapping("/agreementUnitValveHistory")
public class AgreementUnitValveHistoryController extends BaseController {
    @Autowired
    private AgreementUnitValveHistoryService agreementUnitValveHistoryService;

    @ApiOperation("查询单元阀门协议-历史数据列表")
    @PreAuthorize("@ss.hasPermi('agreementUnitValveHistory:agreementUnitValveHistory:list')")
    @PostMapping("/listAgreementUnitValveHistory")
    public TableDataInfo<AgreementUnitValveHistoryListVo> listAgreementUnitValveHistory(@Validated @RequestBody AgreementUnitValveHistoryListDto dto) {
        startPagePost(dto);
        return agreementUnitValveHistoryService.selectAgreementUnitValveHistoryList(dto);
    }

    @ApiOperation("导出单元阀门协议-历史数据列表")
    @PreAuthorize("@ss.hasPermi('agreementUnitValveHistory:agreementUnitValveHistory:export')")
    @Log(title = "单元阀门协议-历史数据", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAgreementUnitValveHistory")
    public void exportAgreementUnitValveHistory(HttpServletResponse response, AgreementUnitValveHistoryListDto dto) {
        TableDataInfo<AgreementUnitValveHistoryListVo> list = agreementUnitValveHistoryService.selectAgreementUnitValveHistoryList(dto);
        ExcelUtil<AgreementUnitValveHistoryListVo> util = new ExcelUtil<AgreementUnitValveHistoryListVo>(AgreementUnitValveHistoryListVo.class);
        util.exportExcel(response, list.getRows(), "单元阀门协议-历史数据数据");
    }

    @ApiOperation("获取单元阀门协议-历史数据详细信息")
    @PreAuthorize("@ss.hasPermi('agreementUnitValveHistory:agreementUnitValveHistory:query')")
    @GetMapping(value = "/getAgreementUnitValveHistoryById")
    public R<AgreementUnitValveHistoryInfoVo> getAgreementUnitValveHistoryById(@RequestParam("id") Long id) {
        return R.ok(agreementUnitValveHistoryService.selectAgreementUnitValveHistoryById(id));
    }

    @ApiOperation("新增单元阀门协议-历史数据")
    @PreAuthorize("@ss.hasPermi('agreementUnitValveHistory:agreementUnitValveHistory:add')")
    @Log(title = "单元阀门协议-历史数据", businessType = BusinessType.INSERT)
    @PostMapping("addAgreementUnitValveHistory")
    public AjaxResult addAgreementUnitValveHistory(@Validated @RequestBody AgreementUnitValveHistoryAddDto dto) {
        return toAjax(agreementUnitValveHistoryService.insertAgreementUnitValveHistory(dto));
    }

    @ApiOperation("修改单元阀门协议-历史数据")
    @PreAuthorize("@ss.hasPermi('agreementUnitValveHistory:agreementUnitValveHistory:edit')")
    @Log(title = "单元阀门协议-历史数据", businessType = BusinessType.UPDATE)
    @PostMapping("editAgreementUnitValveHistory")
    public AjaxResult editAgreementUnitValveHistory(@Validated @RequestBody AgreementUnitValveHistoryUpdDto dto) {
        return toAjax(agreementUnitValveHistoryService.updateAgreementUnitValveHistory(dto));
    }

    @ApiOperation("删除单元阀门协议-历史数据")
    @PreAuthorize("@ss.hasPermi('agreementUnitValveHistory:agreementUnitValveHistory:remove')")
    @Log(title = "单元阀门协议-历史数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/delAgreementUnitValveHistory")
    public AjaxResult delAgreementUnitValveHistory(@RequestParam Long[] ids) {
        return toAjax(agreementUnitValveHistoryService.deleteAgreementUnitValveHistoryByIds(ids));
    }
}
